﻿

Namespace YahooManaged.Finance.Indicators

    ''' <summary>
    ''' Bollinger Bands Indicator
    ''' </summary>
    ''' <remarks></remarks>
    Public Class BB
        Inherits StD

        Public Overrides ReadOnly Property Name() As String
            Get
                Return "Bollinger Bands"
            End Get
        End Property

        Public Overrides ReadOnly Property IsRealative As Boolean
            Get
                Return False
            End Get
        End Property

        Public Overrides Function Calculate(ByVal values As IEnumerable(Of KeyValuePair(Of Date, Double))) As Dictionary(Of Date, Double)()
            Dim bbResultUpper As New Dictionary(Of Date, Double)
            Dim bbResultLower As New Dictionary(Of Date, Double)

            Dim baseResults = MyBase.Calculate(values)
            Dim stdResult As Dictionary(Of Date, Double) = baseResults(0)
            Dim maResult As Dictionary(Of Date, Double) = baseResults(1)
            Dim histQuotes As New List(Of KeyValuePair(Of Date, Double))(baseResults(2))

            If histQuotes.Count > 0 Then
                For Each hq In histQuotes
                    bbResultUpper.Add(hq.Key, maResult(hq.Key) + stdResult(hq.Key))
                    bbResultLower.Add(hq.Key, maResult(hq.Key) - stdResult(hq.Key))
                Next
            End If

            Return New Dictionary(Of Date, Double)() {bbResultUpper, bbResultLower, stdResult, maResult, baseResults(2)}
        End Function


        Public Overrides Function ToString() As String
            Return Me.Name & " " & Me.Period
        End Function
    End Class

End Namespace